﻿using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace Ipmce.RemoteVoting.Frontend.VotingLibrary
{
	public class ConfirmationIdCreator : IConfirmationIdCreator
	{
		public string Create(string uniqueId, long candidateId, DateTime votingTime)
		{
			var firstPartBytes = Encoding.UTF8.GetBytes(uniqueId);
			var secondPart = candidateId + votingTime.Minute;
			var secondPartBytes = BitConverter.GetBytes(secondPart);
			var wholeSource = firstPartBytes.Concat(secondPartBytes).ToArray();
			var hasher = new SHA1CryptoServiceProvider();
			var hash = hasher.ComputeHash(wholeSource);
			return Convert.ToBase64String(hash);
		}
	}
}